home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / t_os / gpen32k / source.exe / LIB / OSRC / OTIFFLOA.C < prev    next >
C/C++ Source or Header  |  1993-08-01  |  2KB  |  95 lines

  1. /************************************************************
  2. *   共通一般ライブラリー                OKOME System 2      *
  3. ************************************************************/
  4.  
  5. #include    <stdio.h>
  6. #include    <string.h>
  7. #include    <math.h>
  8. #include    <EGB.H>
  9. #include    <tifflib.h>
  10. #include    <normlib.h>
  11.  
  12. int tiffload(char *name, int xf, int yf)
  13. {
  14.     char p[2048];
  15.     int i, ofs, tags, x, y, pix, y2=0, gm;
  16. /*    int ask=0, pal=0, palof=0, size=0;    */
  17.  
  18.     FILE *fp;
  19.     if ((fp = fopen(name, "rb")) == NULL)    {
  20.         fclose(fp);
  21.         return (-1);
  22.     }
  23.  
  24.     fread(p, 1, 8, fp);        /*    識別    */
  25.     if (strncmp( p, "II*", 3) != 0)    {
  26.         fclose(fp);
  27.         return (-2);
  28.     }
  29.     ofs = DWORD(p + 4);
  30.     fseek( fp, ofs, SEEK_SET );
  31.     fread( &p[8], 1, 2, fp );
  32.     for ( tags = WORD(p + 8); tags>0; tags--)    {
  33.         fread( p, 1, 12, fp );
  34.         i = DWORD(p + 8);
  35.         switch(WORD(p))    {
  36.         case 0:
  37.             tags = 0;
  38.             break;
  39.         case 0x100:
  40.             x = i;
  41.             break;
  42.         case 0x101:
  43.             y = i;
  44.             break;
  45.         case 0x102:
  46.             pix = i;
  47.             break;
  48. /*        case 0x103:
  49.             ask = i;
  50.             break;    */
  51. /*        case 0x106:
  52.             pal = i;
  53.             break;    */
  54.         case 0x111:
  55.             ofs = i;
  56.             break;
  57.         case 0x116:
  58.             y2 = i;
  59.             break;
  60. /*        case 0x117:
  61.             size = i;
  62.             break;    */
  63. /*        case 0x140:
  64.             palof = i;
  65.             break;    */
  66.         }
  67.     }
  68.     i = EGB_getWritePage(0,0);
  69.     i = (EGB_getResolution( NULL, NULL ) >> (i*8)) & 0xff;
  70.     EGB_getModeInfo( i, NULL,NULL, NULL,NULL, &gm);
  71.     if ((1<<pix) == gm || (pix == 16 && gm == 32768))
  72.     {
  73.         fseek( fp, ofs, SEEK_SET );
  74.         for ( y2 = 0; y2 <= y; y2++ )    {
  75.             fread( p, 1, ceil( x*pix/8.0 ), fp );
  76.             egbput(xf, yf+y2, xf+x, yf+y2, p);
  77.         }
  78.         i = 0;
  79.     }    else    {
  80.         if (pix == 1)
  81.         {
  82.             fseek( fp, ofs, SEEK_SET );
  83.             for ( y2 = 0; y2 <= y; y2++ )    {
  84.                 fread( p, 1, ceil( x/8.0 ), fp );
  85.                 egbputc(xf, yf+y2, xf+x, yf+y2, p);
  86.             }
  87.             i = 0;
  88.         }    else    {
  89.             i = pix;
  90.         }
  91.     }
  92.     fclose(fp);
  93.     return (i);
  94. }
  95.